using System;
using System.Collections.Generic;
using System.Text;
using Entites;
using DAL;
using Utility;

namespace BUS
{
   public class DanhMucBUS
    {
         public static void Insert(DanhMuc dm)
        {
            DanhMucDAL dmDAL = new DanhMucDAL();
            dmDAL.Insert(dm);
        }
        public static void Update(DanhMuc dm)
        {
            DanhMucDAL dmDAL = new DanhMucDAL();
            dmDAL.Update(dm);
        }
        public static void Delete(int iD)
        {
            DanhMucDAL dmDAL = new DanhMucDAL();
            dmDAL.Delete(iD);
        }
        public static tbDanhMucCollection Get(string where,
            int pageindex,
            int pagesize,
            string orderby,
            string orderdirection,
            out int total)
        {
            DanhMucDAL dmDAL = new DanhMucDAL();
            return dmDAL.Get(where, pageindex, pagesize, orderby, orderdirection, out total);
        }
        public static tbDanhMucCollection GetAll()
        {
            int total = 0;
            Criteria cri = new Criteria();
            DanhMucDAL dmDAL = new DanhMucDAL();
            return dmDAL.Get(cri.Criter, 0, 0, tbDanhMucColumns.MaDM.ToString(), OrderDirection.ASC.ToString(), out total);
        }
        public static DanhMuc GetByID(int iD)
        {
            int total = 0;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, tbDanhMucColumns.MaDM.ToString(), Condition.EQUAL, iD);
            DanhMucDAL dmDAL = new DanhMucDAL();
            tbDanhMucCollection danhmuccollection = dmDAL.Get(cri.Criter,
                  0, 0, tbDanhMucColumns.MaDM.ToString(), OrderDirection.ASC.ToString(), out total);
            if (danhmuccollection.Count > 0)
                return danhmuccollection[0];
            return null;
        }
        public static tbDanhMucCollection GetLimited(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            DanhMucDAL dmDAL = new DanhMucDAL();
            return dmDAL.Get(cri.Criter, 1, number,
             tbDanhMucColumns.MaDM.ToString(), OrderDirection.DESC.ToString(), out total);
        }
        public static tbDanhMucCollection GetPromotion(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            DanhMucDAL dmDAL = new DanhMucDAL();
            return dmDAL.Get(cri.Criter, 1, number,
               tbDanhMucColumns.MaDM.ToString(), OrderDirection.DESC.ToString(), out total);
        }
    }
    
}
